<?php
defined('IN_IA') or exit('Access Denied');
set_time_limit(600);
global $_W, $_GPC;
$setting = $this->baseset($_W['uniacid']);
load()->func('communication');
for ($i = 1; $i <= 1; $i++) {
	$dtkurl = "http://api.dataoke.com/index.php?r=Port/index&type=top100&appkey=" . $setting['dtk_key'] . "&v=2";
	$resp = ihttp_get($dtkurl);
	if (is_error($resp)) {
		$this->json_exit(0, $resp["message"]);
	}
	$dtkData = json_decode($resp['content'], true);
	if ($dtkData['data']['total_num'] >= 1) {
		$result = $dtkData['result'];
		$total = $dtkData['data']['total_num'];
		$total_i = 0;
		foreach ($result as $key => $item) {
			if ($total_i < $total) {
				if ($item['GoodsID'] == '') {
					break;
				}
				if ($item['GoodsID'] != '') {
					$cate = pdo_fetch('select * from ' . tablename('bsht_tbk_all_caiji') . " where uniacid = '{$uniacid}' AND itemid = '{$item['GoodsID']}' and uniacid = '{$_W['uniacid']}' limit 1");
					$newurl = "http://uland.taobao.com/coupon/edetail?activityId=" . $item['Quan_id'] . "&pid=" . $setting['tb_pid'] . "&itemId=" . $item['GoodsID'] . "&src=pgy_pgyqf&dx=1";
					$logo = $item['Pic'];
					$text = $item['D_title'] . "【券后价￥" . $item['Price'] . "】";
					if ($item['Commission_queqiao'] > $item['Commission_jihua']) {
						$bili = $item['Commission_queqiao'];
					} else {
						$bili = $item['Commission_jihua'];
					}
					$data = array('atime' => TIMESTAMP, 'uniacid' => $_W['uniacid'], 'displayorder' => '0', 'itemid' => $item['GoodsID'], 'title' => $item['Title'], 'd_title' => $item['D_title'], 'itempic' => $item['Pic'], 'cate_id' => $item['Cid'], 'shoptitle' => $item['Introduce'], 'itemfee' => $item['Org_Price'], 'itemfee2' => $item['Price'], 'itemmsell' => $item['Sales_num'], 'istmall' => $item['IsTmall'], 'itemyhj_fee' => $item['Quan_price'], 'itemyhj_zl' => $item['Quan_surplus'], 'itemyhj_yl' => $item['Quan_surplus'] - $item['Quan_receive'], 'itemyhj_re' => $item['Quan_receive'], 'link_jihua' => $item['Jihua_link'], 'com_jihua' => $item['Commission_jihua'], 'com_queqiao' => $item['Commission_queqiao'], 'status' => 1, 'wenan' => $item['Introduce'], 'itemyhj_tit' => $item['Quan_condition'], 'itemyhj_stime' => TIMESTAMP, 'itemyhj_etime' => $item['Quan_time'], 'itemyhj_url' => $newurl, 'itemurl' => $newurl, 'quan_link' => $item['Quan_link'], 'shouru_bili' => $bili, 'shouru_yongjin' => $item['Org_Price'] * $bili / 100, 'quan_id' => $item['Quan_id'], 'maijia_id' => $item['SellerID'], 'fm' => 'dtk',);
					$data['itemsurl'] = $newurl;
					$data['itemyhj_tkl'] = '';
					$data['itemtkl'] = '';
					if (empty($cate)) {
						pdo_insert('bsht_tbk_all_caiji', $data);
						$cateid = pdo_insertid();
					} else {
						pdo_update($this->modulename . '_all_caiji', $data, array('id' => $cate['id']));
						$cateid = $cate['id'];
					}
				}
				$total_i++;
			} else {
			}
		}
	} else {
	}
}
message('同步成功！', referer(), 'success');